package com.yuanli.cosmeticmirror.persenter;

import androidx.lifecycle.LifecycleOwner;

import com.comenjoysoft.baselibrary.listener.CallbackListener;
import com.comenjoysoft.baselibrary.presenter.BasePresenter;
import com.mob.MobSDK;
import com.yuanli.cosmeticmirror.R;
import com.yuanli.cosmeticmirror.bean.videoBean;
import com.yuanli.cosmeticmirror.bean.videoInfoBean;
import com.yuanli.cosmeticmirror.model.biz.IVideoBiz;
import com.yuanli.cosmeticmirror.model.impl.VideoImpl;
import com.yuanli.cosmeticmirror.model.iview.IVideoView;

import cn.sharesdk.onekeyshare.OnekeyShare;


public class VideoPersenter extends BasePresenter<IVideoView> {
    private final IVideoBiz biz;
    /**
     * 获取教程详情
     */
    public static final int TUTORIAL_DETAIL = 1;
    /**
     * 点赞
     */
    public static final int TUTORIAL_LIKE = 2;
    /**
     * 取消点赞
     */
    public static final int TUTORIAL_CANCEL_LIKE = 3;
    /**
     * 收藏
     */
    public static final int TUTORIAL_COLLECT = 4;
    /**
     * 取消收藏
     */
    public static final int TUTORIAL_CANCEL_COLLECT = 5;

    public VideoPersenter(IVideoView view, LifecycleOwner owner) {
        attachView(view);
        biz = new VideoImpl(owner);
    }

    public void getTutorialDetails(String id) {
        biz.getTutorialDetails(id, new CallbackListener<videoInfoBean>() {
            @Override
            public void success(videoInfoBean object) {
                mView.onSuccess(object, TUTORIAL_DETAIL);
            }

            @Override
            public void failed(Object object) {
                mView.onError("获取教程详情失败", TUTORIAL_DETAIL);
            }
        });
    }

    public void like(String id) {
        biz.like(id, new CallbackListener<videoBean>() {
            @Override
            public void success(videoBean object) {
                mView.onSuccess(null, TUTORIAL_LIKE);
            }

            @Override
            public void failed(Object object) {
                mView.onError("点赞失败", TUTORIAL_LIKE);
            }
        });
    }

    public void cancelLike(String id) {
        biz.cancelLike(id, new CallbackListener<videoBean>() {
            @Override
            public void success(videoBean object) {
                mView.onSuccess(null, TUTORIAL_CANCEL_LIKE);
            }

            @Override
            public void failed(Object object) {
                mView.onError("取消点赞失败", TUTORIAL_CANCEL_LIKE);
            }
        });
    }

    public void cancelCollect(String id) {
        biz.cancelCollect(id, new CallbackListener<videoBean>() {
            @Override
            public void success(videoBean object) {
                mView.onSuccess(null, TUTORIAL_CANCEL_COLLECT);
            }

            @Override
            public void failed(Object object) {
                mView.onError("取消收藏失败", TUTORIAL_CANCEL_COLLECT);
            }
        });
    }

    public void collect(String id) {
        biz.collect(id, new CallbackListener<videoBean>() {
            @Override
            public void success(videoBean object) {
                mView.onSuccess(null, TUTORIAL_COLLECT);
            }

            @Override
            public void failed(Object object) {
                mView.onError("收藏失败", TUTORIAL_COLLECT);
            }
        });
    }


    public void addRecord(String id) {
        biz.addRecord(id);

    }


    /**
     * 分享到不同平台
     *
     * @param platformName 平台名称
     */
    public void share(String videoText, String videoUrl, String imgUrl, String platformName) {
        OnekeyShare oks = new OnekeyShare();
        oks.setPlatform(platformName);
        oks.setTitle("化妆镜");
        oks.setImageUrl(imgUrl);
        oks.setTitleUrl(videoUrl);
        oks.setText(videoText);
        oks.setUrl(videoUrl);
//        oks.setFilePath(videoUrl);
        // 启动分享GUI
        oks.show(MobSDK.getContext());
    }
}
